package com.hzit.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.filter.HiddenHttpMethodFilter;

/**
 * 类名：
 * 作者：WF
 * 功能：重写了redis的序列化机制，便于使用
 */
@Configuration
public class HzitRedisConfig {

	// @Bean
	// public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
	// 	RedisTemplate<Object, Object> template = new RedisTemplate<>();
	// 	template.setConnectionFactory(redisConnectionFactory);
	// 	template.setKeySerializer(new StringRedisSerializer());                  // 存放key是字符串
	// 	template.setValueSerializer(new GenericJackson2JsonRedisSerializer());   //  设置值的序列化器
	// 	template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer()); //  设置hashkey
	// 	template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); // 设置hash的value
	// 	return template;
	// }
	// 重写restFul中的表单隐藏域参数名字
	@Bean
	public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
		OrderedHiddenHttpMethodFilter methodFilter = new OrderedHiddenHttpMethodFilter();
		methodFilter.setMethodParam("_m");
		return methodFilter;
	}
}
